﻿// Control20Dlg_2.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "Control20Dlg_2.h"
#include "afxdialogex.h"


// CControl20Dlg_2 对话框

IMPLEMENT_DYNAMIC(CControl20Dlg_2, CDialogEx)

CControl20Dlg_2::CControl20Dlg_2(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONTROL_20_2, pParent)
{

}

CControl20Dlg_2::~CControl20Dlg_2()
{
}

void CControl20Dlg_2::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, m_editStep);
	DDX_Control(pDX, IDC_COMBO1, m_combPosNo);
	DDX_Control(pDX, IDC_COMBO2, m_combCircle);
	DDX_Control(pDX, IDC_EDIT2, m_editX);
	DDX_Control(pDX, IDC_EDIT3, m_editY);
	DDX_Control(pDX, IDC_EDIT4, m_editZ);
}


BEGIN_MESSAGE_MAP(CControl20Dlg_2, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON6, &CControl20Dlg_2::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON4, &CControl20Dlg_2::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CControl20Dlg_2::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON10, &CControl20Dlg_2::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON26, &CControl20Dlg_2::OnBnClickedButton26)
	ON_BN_CLICKED(IDC_BUTTON2, &CControl20Dlg_2::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CControl20Dlg_2::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON33, &CControl20Dlg_2::OnBnClickedButton33)
	ON_BN_CLICKED(IDC_BUTTON34, &CControl20Dlg_2::OnBnClickedButton34)
	ON_BN_CLICKED(IDC_BUTTON24, &CControl20Dlg_2::OnBnClickedButton24)
	ON_BN_CLICKED(IDC_BUTTON25, &CControl20Dlg_2::OnBnClickedButton25)
	ON_BN_CLICKED(IDC_BUTTON8, &CControl20Dlg_2::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CControl20Dlg_2::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON12, &CControl20Dlg_2::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON23, &CControl20Dlg_2::OnBnClickedButton23)
	ON_BN_CLICKED(IDC_BUTTON7, &CControl20Dlg_2::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON38, &CControl20Dlg_2::OnBnClickedButton38)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON32, &CControl20Dlg_2::OnBnClickedButton32)
	ON_BN_CLICKED(IDC_BUTTON31, &CControl20Dlg_2::OnBnClickedButton31)
	ON_BN_CLICKED(IDC_BUTTON29, &CControl20Dlg_2::OnBnClickedButton29)
	ON_BN_CLICKED(IDC_BUTTON30, &CControl20Dlg_2::OnBnClickedButton30)
	ON_BN_CLICKED(IDC_BUTTON27, &CControl20Dlg_2::OnBnClickedButton27)
	ON_BN_CLICKED(IDC_BUTTON28, &CControl20Dlg_2::OnBnClickedButton28)
	ON_BN_CLICKED(IDC_BUTTON1, &CControl20Dlg_2::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON35, &CControl20Dlg_2::OnBnClickedButton35)
	ON_BN_CLICKED(IDC_BUTTON37, &CControl20Dlg_2::OnBnClickedButton37)
	ON_BN_CLICKED(IDC_BUTTON39, &CControl20Dlg_2::OnBnClickedButton39)
	ON_BN_CLICKED(IDC_BUTTON40, &CControl20Dlg_2::OnBnClickedButton40)
END_MESSAGE_MAP()


// CControl20Dlg_2 消息处理程序


BOOL CControl20Dlg_2::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_combPosNo.ResetContent();
	m_combPosNo.AddString(L"0:待机位");
	m_combPosNo.AddString(L"1:模组Plasma起点");
	m_combPosNo.AddString(L"2:镜头Plasma起点");
	m_combPosNo.AddString(L"3:点胶起点");
	m_combPosNo.AddString(L"4:称重点胶起点");
	m_combPosNo.AddString(L"5:白场测试位置");
	m_combPosNo.AddString(L"6:对针起点");
	m_combPosNo.SetCurSel(0);


	m_combCircle.ResetContent();
	m_combCircle.AddString(L"0:点胶");
	m_combCircle.AddString(L"1:Plasma");
	m_combCircle.SetCurSel(0);
	SetTimer(TIMER_ID_AXIS_STATUS_3, 500, NULL);
	return TRUE;
}


void CControl20Dlg_2::OnBnClickedButton6()
{
	gSystemMgr.m_cIo.SetOutputIo(21, ON);
	gSystemMgr.m_cIo.SetOutputIo(22, OFF);
}


void CControl20Dlg_2::OnBnClickedButton4()
{
	gSystemMgr.m_cIo.SetOutputIo(19, ON);
	gSystemMgr.m_cIo.SetOutputIo(20, OFF);
}


void CControl20Dlg_2::OnBnClickedButton5()
{
	gSystemMgr.m_cIo.SetOutputIo(20, ON);
	gSystemMgr.m_cIo.SetOutputIo(19, OFF);
}


void CControl20Dlg_2::OnBnClickedButton10()
{
	gSystemMgr.m_cIo.SetOutputIo(29, ON);
}


void CControl20Dlg_2::OnBnClickedButton26()
{
	gSystemMgr.m_cIo.SetOutputIo(29, OFF);
}


void CControl20Dlg_2::OnBnClickedButton2()
{
	gSystemMgr.m_cIo.SetOutputIo(30, ON);
	gSystemMgr.m_cIo.SetOutputIo(31, OFF);
}


void CControl20Dlg_2::OnBnClickedButton3()
{
	gSystemMgr.m_cIo.SetOutputIo(31, ON);
	gSystemMgr.m_cIo.SetOutputIo(30, OFF);
}


void CControl20Dlg_2::OnBnClickedButton33()
{
	gSystemMgr.m_cIo.SetOutputIo(22, ON);
	gSystemMgr.m_cIo.SetOutputIo(21, OFF);
}


void CControl20Dlg_2::OnBnClickedButton34()
{
	//if (gSystemMgr.Y38 == OFF) {
	//	gSystemMgr.m_cIo.SetOutputIo(38, ON);
	//}
	//else {
		gSystemMgr.m_cIo.SetOutputIo(38, OFF);
	//}
}


void CControl20Dlg_2::OnBnClickedButton24()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton25()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_X1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton8()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton9()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Y1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton12()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton23()
{
	CString cstr;
	m_editStep.GetWindowTextW(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	gSystemMgr.m_vCMotor[MOTOR_Z1].MotorMoveStep();
}


void CControl20Dlg_2::OnBnClickedButton7()
{
	//if (gSystemMgr.m_bMotorErrorFlag || !gSystemMgr.m_bHomeFlag)
	//	return;
	int n;
	n = m_combPosNo.GetCurSel();
	gSystemMgr.m_nButtonValue = 220 + n;
}


void CControl20Dlg_2::OnBnClickedButton38()
{
	//if (gSystemMgr.m_bMotorErrorFlag || !gSystemMgr.m_bHomeFlag)
	//	return;
	int n;
	n = m_combCircle.GetCurSel();
	gSystemMgr.m_nButtonValue = 230 + n;
}


void CControl20Dlg_2::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_ID_AXIS_STATUS_3)
	{
		double nDis = gSystemMgr.m_vCMotor[MOTOR_X1].m_nCurPositon;
		CString cstr;
		cstr.Format(L"%.1f", nDis);
		m_editX.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Y1].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editY.SetWindowTextW(cstr);
		nDis = gSystemMgr.m_vCMotor[MOTOR_Z1].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editZ.SetWindowTextW(cstr);
	}

	CDialogEx::OnTimer(nIDEvent);
}


void CControl20Dlg_2::OnCancel()
{
	KillTimer(TIMER_ID_AXIS_STATUS_3);

	CDialogEx::OnCancel();
}


void CControl20Dlg_2::OnBnClickedButton32()
{
	gSystemMgr.m_cIo.SetOutputIo(28, ON);
	gSystemMgr.m_cIo.SetOutputIo(27, OFF);
}


void CControl20Dlg_2::OnBnClickedButton31()
{
	gSystemMgr.m_cIo.SetOutputIo(27, ON);
	gSystemMgr.m_cIo.SetOutputIo(28, OFF);
}


void CControl20Dlg_2::OnBnClickedButton29()
{
	gSystemMgr.m_cIo.SetOutputIo(23, ON);
	gSystemMgr.m_cIo.SetOutputIo(24, OFF);
}


void CControl20Dlg_2::OnBnClickedButton30()
{
	gSystemMgr.m_cIo.SetOutputIo(24, ON);
	gSystemMgr.m_cIo.SetOutputIo(23, OFF);
}


void CControl20Dlg_2::OnBnClickedButton27()
{
	gSystemMgr.m_cIo.SetOutputIo(25, ON);
	gSystemMgr.m_cIo.SetOutputIo(26, OFF);
}


void CControl20Dlg_2::OnBnClickedButton28()
{
	gSystemMgr.m_cIo.SetOutputIo(26, ON);
	gSystemMgr.m_cIo.SetOutputIo(25, OFF);
}


void CControl20Dlg_2::OnBnClickedButton1()
{
	gSystemMgr.m_vCMotor[MOTOR_X1].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Y1].StopMove();
	gSystemMgr.m_vCMotor[MOTOR_Z1].StopMove();
}


void CControl20Dlg_2::OnBnClickedButton35()
{
	if (gSystemMgr.Y18 == OFF) {
		gSystemMgr.m_cIo.SetOutputIo(18, ON);
	}
	else {
		gSystemMgr.m_cIo.SetOutputIo(18, OFF);
	}
}


void CControl20Dlg_2::OnBnClickedButton37()
{
	gSystemMgr.m_nButtonValue = 20;
}


void CControl20Dlg_2::OnBnClickedButton39()
{
	gSystemMgr.m_nButtonValue = 235;
}


void CControl20Dlg_2::OnBnClickedButton40()
{
	gSystemMgr.m_nButtonValue = 236;
}
